package com.wang.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.wang.pojo.*;
import com.wang.response.PageResult;
import com.wang.response.Result;
import com.wang.response.ResultResponse;
import com.wang.service.CourseService;
import com.wang.service.LiveService;
import com.wang.service.SpecialistService;
import com.wang.utils.FastDFSClient;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@Api(tags = "健康课堂管理接口")
//http://localhost:7070/swagger-ui/index.html#/
public class CourseController {
    @Autowired
    SpecialistService specialistService;
    @Autowired
    FastDFSClient fastDFSClient;

    @XxlJob("test2")
    @PostMapping("test1")
    public String test1( @RequestBody String param){
        System.out.println("course执行成功"+param);
        return param+"success";
    }

    @PostMapping("uploadFile")
    @Operation(summary = "fastdfs上传")
    public String uploadFile( @RequestParam("file") MultipartFile multipartFile) throws IOException {
        String upload = fastDFSClient.upload(multipartFile);
        return upload;
    }

    @PostMapping("addSpecialist")
    @Operation(summary = "添加或修改专家信息")
    public ResultResponse addOrUpdateSpecialist(@RequestBody Specialist specialist){
        return specialistService.addOrUpdateSpecialist(specialist);
    }
    @PostMapping("delSpecialist/{specialistId}")
    @Operation(summary = "删除专家")
    public ResultResponse delSpecialist( @PathVariable Integer specialistId){
        return specialistService.delSpecialist(specialistId);
    }

    @PostMapping("getSpecialistAll/{pageNum}/{pageSize}")
    @Operation(summary = "专家信息列表")
    public ResultResponse getSpecialistAll(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return specialistService.getSpecialistAll(pageNum,pageSize);
    }
    @Autowired
    CourseService courseService;

    @PostMapping("addCourse")
    @Operation(summary = "发布文章或录播")
    public ResultResponse addCourse( @RequestBody CourseDTO courseDTO){
        return courseService.addCourse(courseDTO);
    }
    @PostMapping("addAttention")
    @Operation(summary = "关注专家")
    public ResultResponse addAttention( @RequestBody Attention attention){
        return courseService.addAttention(attention);
    }

    @PostMapping("cancelAttention")
    @Operation(summary = "取关专家")
    public ResultResponse cancelAttention( @RequestBody Attention attention){
        return courseService.cancelAttention(attention);
    }

    @PostMapping("searchCourse/{pageNum}/{pageSize}")
    @Operation(summary = "查询所有课堂")
    public ResultResponse searchCourse( @PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return courseService.searchCourse(pageNum,pageSize);
    }
    @Autowired
    LiveService liveService;

    @PostMapping("addLive")
    @Operation(summary = "预约直播")
    public ResultResponse addLive( @RequestBody Live live){
        return liveService.addLive(live);
    }
    @PostMapping("getLiveUrlBySpecialistId/{specialistId}")
    @Operation(summary = "通过专家id获取推流")
    public ResultResponse getLiveUrlBySpecialistId( @PathVariable Integer specialistId){
        return liveService.getLiveUrlBySpecialistId(specialistId);
    }

    @PostMapping("getLiveUrlByLivId/{liveId}")
    @Operation(summary = "通过直播id获取推流")
    public ResultResponse getLiveUrlByLivId( @PathVariable Integer liveId){
        return liveService.getLiveUrlByLivId(liveId);
    }

    @PostMapping("callback")
    @Operation(summary = "添加回放")
    public String callback( @RequestBody String json){
       return liveService.callback(json);
    }

    @PostMapping("finishLive/{liveId}")
    @Operation(summary = "结束直播(修改直播状态)")
    public ResultResponse finishLive( @PathVariable Integer liveId){
        return liveService.finishLive(liveId);
    }
    @PostMapping("showLiveAll/{pageNum}/{pageSize}")
    @Operation(summary = "显示直播信息")
    public ResultResponse showLiveAll( @PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return liveService.showLiveAll(pageNum,pageSize);
    }

    @PostMapping("seeReplay/{specialistId}")
    @Operation(summary = "专家id获取回放")
    public ResultResponse seeReplay( @PathVariable Integer specialistId){
        return liveService.seeReplay(specialistId);
    }


}
